home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
3100
/
3100.xpi
/
chrome
/
content
/
js
/
options.js
< prev
Wrap
Text File
|
2010-01-23
|
17KB
|
547 lines
// Click&Clean, MIT, <http://www.hotcleaner.com/>. Copyright Mixesoft(c)Project 2004-2010 <http://www.mixesoft.com/>
addEventListener('load', function() {
var bSave = true;
// set window size
innerWidth = $('page').clientWidth;
innerHeight = $('page').clientHeight;
localize();
readPrefs(false);
addEventListener('unload', function() {
if (bSave)
writePrefs();
}, false);
// home
$('home').addEventListener('mouseover', function() {
this.style.backgroundImage = 'url(img/home_over.gif)';
}, 0);
$('home').addEventListener('mouseout', function() {
this.style.backgroundImage = 'url(img/home_out.gif)';
}, 0);
$('home').addEventListener('click', function() {
if (navigator.language == 'ru')
newTab('http://www.hotcleaner.com/ru_clickclean_firefox.html');
else
newTab('http://www.hotcleaner.com/clickclean_firefox.html');
}, 0);
// forum
$('forum').addEventListener('mouseover', function() {
this.style.backgroundImage = 'url(img/forum_over.gif)';
}, 0);
$('forum').addEventListener('mouseout', function() {
this.style.backgroundImage = 'url(img/forum_out.gif)';
}, 0);
$('forum').addEventListener('click', function() {
newTab('http://www.hotcleaner.com/app/clickclean_forum.php?b=f&l='+navigator.language);
}, 0);
// twitter
$('twitter').addEventListener('mouseover', function() {
this.style.backgroundImage = 'url(img/twitter_over.gif)';
}, 0);
$('twitter').addEventListener('mouseout', function() {
this.style.backgroundImage = 'url(img/twitter_out.gif)';
}, 0);
$('twitter').addEventListener('click', function() {
newTab('http://twitter.com/clickclean');
}, 0);
// contact
$('contact').addEventListener('mouseover', function() {
this.style.backgroundImage = 'url(img/contact_over.gif)';
}, 0);
$('contact').addEventListener('mouseout', function() {
this.style.backgroundImage = 'url(img/contact_out.gif)';
}, 0);
$('contact').addEventListener('click', function() {
if (navigator.language == 'ru')
newTab('http://www.hotcleaner.com/ru_clickclean.html#contact');
else
newTab('http://www.hotcleaner.com/index.html#contact');
}, 0);
// caption
$('san-cap').addEventListener('click', function() {
clearBrowsingData(8);
}, false);
$('san-enabled').addEventListener('click', setSanStates, false);
$('san-close').addEventListener('click', setSanStates, false);
$('san-ask').addEventListener('click', function() {
$('san-time').disabled = !this.checked;
}, false);
// clear browsing data
$('san-clear').addEventListener('click', function() {
clearLSO();
clearUI(1);
}, false);
$('ext-sanitize').addEventListener('click', setExtStates, false);
$('ext-close').addEventListener('click', setExtStates, false);
// browse
$('ext-browse').addEventListener('click', function() {
var path = openFileDlg();
if (path) {
$('ext-path').value = path;
}
}, false);
// run external app.
$('ext-run').addEventListener('click', function() {
clearLSO();
clearUI(0);
}, false);
// close all windows and tabs
$('adv-tabs').addEventListener('click', function() {
$('adv-tab').disabled = !this.checked;
}, false);
// reset
$('opt-def').addEventListener('click', function() {
readPrefs(true); // read default prefs.
}, 0);
// ok
$('opt-ok').addEventListener('click', function() {
close();
}, 0);
// cancel
$('opt-cancel').addEventListener('click', function() {
bSave = false;
close();
}, 0);
function setSanStates() {
if ($('san-enabled').checked || $('san-close').checked) {
$('san-ask').disabled = $('san-clear').disabled = false;
$('san-time').disabled = !$('san-ask').checked;
}
else {
$('san-time').disabled = $('san-ask').disabled = $('san-clear').disabled = true;
}
}
function setExtStates() {
if ($('ext-sanitize').checked || $('ext-close').checked) {
$('ext-path').disabled = $('ext-browse').disabled = $('ext-arg').disabled = $('ext-run').disabled = false;
}
else {
$('ext-path').disabled = $('ext-browse').disabled = $('ext-arg').disabled =$('ext-run').disabled = true;
}
}
function readPrefs(bDef) {
var prefs;
if (bDef) {
prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getDefaultBranch("extensions.clickclean.");
}
else {
prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.clickclean.");
}
$('san-enabled').checked = prefs.getBoolPref('sanitize');
$('san-close').checked = prefs.getBoolPref('close');
$('san-ask').checked = prefs.getBoolPref('showPrompt');
$('san-time').selectedIndex = prefs.getIntPref('wait');
setSanStates();
$('ext-sanitize').checked = prefs.getBoolPref('useExt');
$('ext-close').checked = prefs.getBoolPref('closeExt');
var path = $('ext-path').value = prefs.getComplexValue("path", Components.interfaces.nsISupportsString).data;
var arg = $('ext-arg').value = prefs.getComplexValue("arg", Components.interfaces.nsISupportsString).data;
setExtStates();
$('adv-lso').checked = prefs.getBoolPref('lso');
$('adv-tabs').checked = prefs.getBoolPref('tabs');
$('adv-tab').checked = prefs.getBoolPref('tab');
$('adv-tab').disabled = !$('adv-tabs').checked;
// ccleaner or wsd
if (path.length < 1) {
if (navigator.platform == 'Win32') {
path = getInstallPath('CCleaner');
if (path) {
$('ext-path').value = path+'\\CCleaner.exe';
$('ext-arg').value = '/auto';
}
else {
path = getInstallPath('Wise Disk Cleaner_is1');
if (path) {
$('ext-path').value = path+'WiseDiskCleaner.exe';
$('ext-arg').value = '-a -p';
}
}
}
}
}
function writePrefs() {
if (bSave) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.clickclean.");
prefs.setBoolPref('sanitize', $('san-enabled').checked);
prefs.setBoolPref('close', $('san-close').checked);
prefs.setBoolPref('showPrompt', $('san-ask').checked);
prefs.setIntPref('wait', $('san-time').selectedIndex );
prefs.setBoolPref('useExt', $('ext-sanitize').checked);
prefs.setBoolPref('closeExt', $('ext-close').checked);
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
str.data = $('ext-path').value;
prefs.setComplexValue("path", Components.interfaces.nsISupportsString, str);
str.data = $('ext-arg').value;
prefs.setComplexValue("arg", Components.interfaces.nsISupportsString, str);
prefs.setBoolPref('lso', $('adv-lso').checked);
prefs.setBoolPref('tabs', $('adv-tabs').checked);
prefs.setBoolPref('tab', $('adv-tab').checked);
}
}
function localize() {
var s = $('bundle_clickclean');
if (s) {
document.title = s.getString('doctitle');
// localize menu
$('home-text').textContent = s.getString('home-text');
$('forum-text').textContent = s.getString('forum-text');
$('twitter-text').textContent = s.getString('twitter-text');
$('contact-text').textContent = s.getString('contact-text');
// localize private data box
$('san-cap').textContent = s.getString('san-cap');
$('san-enabled-desc').textContent = s.getString('san-enabled-desc');
$('san-close-desc').textContent = s.getString('san-close-desc');
$('san-ask-desc').textContent = s.getString('san-ask-desc');
$('san-time-desc').textContent = s.getString('san-time-desc');
$('san-time-inf').textContent = s.getString('san-time-inf');
$('san-clear').textContent = s.getString('san-clear');
// localize ext. app. box
$('ext-cap').textContent = s.getString('ext-cap');
$('ext-sanitize-desc').textContent = s.getString('ext-sanitize-desc');
$('ext-close-desc').textContent = s.getString('ext-close-desc');
$('ext-path-desc').textContent = s.getString('ext-path-desc');
$('ext-arg-desc').textContent = s.getString('ext-arg-desc');
$('ext-run').textContent = s.getString('ext-run');
// advanced box
$('adv-cap').textContent = s.getString('adv-cap');
$('adv-lso-desc').textContent = s.getString('adv-lso-desc');
$('adv-tabs-desc').textContent = s.getString('adv-tabs-desc');
$('adv-tab-desc').textContent = s.getString('adv-tab-desc');
// localize btns.
$('opt-def').textContent = s.getString('opt-def');
$('opt-ok').textContent = s.getString('opt-ok');
$('opt-cancel').textContent = s.getString('opt-cancel');
// localize tooltips
initTip($('home'), s.getString('home'), 0, 0, 280);
initTip($('forum'), s.getString('forum'), 0, 0, 150);
initTip($('twitter'), s.getString('twitter'), -140, 0, 150);
initTip($('contact'), s.getString('contact'), -90, 0, 100);
initTip($('ext-path'), s.getString('ext-path'), -110, 0, 160);
initTip($('ext-arg'), s.getString('ext-arg'),-110, 0, 140);
initTip($('opt-def'), s.getString('opt-def-title'), 0, -80, 160);
}
}
function initTip(obj, strTip, iLeft, iTop, iWidth) {
var tid = 0;
var t = $('tip');
obj.addEventListener('mousemove', function(e) {
t.style.top = e.pageY+23+((iTop)? iTop:0)+'px';
t.style.left = e.pageX+((iLeft)? iLeft:0)+'px';
if (iWidth)
t.style.width = iWidth+'px';
if (!tid) {
tid = window.setTimeout(function() {
t.textContent = strTip;
t.style.display = 'block';
window.clearTimeout(tid);
tid = window.setTimeout(function() {
t.style.display = 'none';
window.clearTimeout(tid);
}, 2000);
}, 500);
}
}, true);
obj.addEventListener('mouseout', function() {
window.clearTimeout(tid);
tid = 0;
var t = $('tip');
t.style.display = 'none';
}, true);
}
function openFileDlg() {
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
var props = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var OS = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime).OS.toLowerCase();
fp.init(window, 'Choose application' , 0);
if (OS == 'linux') {
fp.displayDirectory = props.get("Desk", Components.interfaces.nsIFile);
}
else if (OS == 'darwin') {
}
else {
fp.appendFilter('Windows executable', '*.exe');
fp.appendFilter('Batch file', '*.bat');
fp.appendFilter('All', '*.*');
fp.displayDirectory = props.get("Desk", Components.interfaces.nsIFile);
}
var rv = fp.show();
if (rv == 0 || rv == 2)
return fp.file.path;
}
function newTab(url)
{
try {
var b = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser").gBrowser;
b.selectedTab = b.addTab(url);
}
catch(e){}
}
function clearBrowsingData(wait) {
var wdlg = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, "chrome://browser/content/sanitize.xul", null, "chrome,centerscreen", null);
wdlg.addEventListener('load', function() {
var tid = 0;
wdlg.addEventListener('unload', function(e) {
// case cancel
if (tid)
wdlg.clearTimeout(tid);
}, false)
var dlg = wdlg.document.getElementsByTagName('prefwindow');
dlg = dlg[0];
if(wait > 7)
return;
if (wait < 1) {
dlg.acceptDialog();
return;
}
var btn = dlg.getButton('accept');
if (btn) {
var i = wait;
var label = btn.label;
function setLabel() {
btn.label = label+' ('+i+')';
if (i < 1)
dlg.acceptDialog();
else {
--i;
tid = wdlg.setTimeout(setLabel, 1000);
}
}
setLabel();
}
}, false);
}
function runExt(path, args) {
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
var proc = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
file.initWithPath(path);
proc.init(file);
proc.run(false, [args], 1);
}
function clearLSO() {
if (!$('adv-lso').checked)
return;
var OS = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime).OS.toLowerCase();
var props = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
var dir, path;
if (OS == 'linux') {
dir = props.get('Home', Components.interfaces.nsIFile);
path = dir.path + "/.macromedia/Flash_Player/#SharedObjects";
rem();
path = dir.path + "/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys"
rem();
}
else if (OS == 'darwin') {
dir = props.get('ULibDir', Components.interfaces.nsIFile);
path = dir.path + "/Preferences/Macromedia/Flash Player/#SharedObjects";
rem();
path = dir.path + "/Preferences/Macromedia/Flash Player/macromedia.com/support/flashplayer/sys"
rem();
}
else { // win
dir = props.get('AppData', Components.interfaces.nsIFile);
path = dir.path + '\\Macromedia\\Flash Player\\#SharedObjects';
rem();
path = dir.path + "\\Macromedia\\Flash Player\\macromedia.com\\support\\flashplayer\\sys"
rem();
}
function rem() {
try {
file.initWithPath(path);
if (file.exists)
file.remove(true);
} catch (e){};
}
}
function clearUI(bSan) {
if ($('adv-tabs').checked) {
var m = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
if (m) {
var recent = m.getMostRecentWindow("navigator:browser");
// enum and close all windows but keep selected
var e = m.getEnumerator('');
if (e) {
var w;
while(e.hasMoreElements()) {
w = e.getNext();
// close tabs
if (w == recent) {
var b = w.gBrowser;
if (!$('adv-tab').checked)
b.selectedTab = b.addTab('about:blank');
b.removeAllTabsBut(b.selectedTab);
}
else
w.close();
}
}
}
}
// run ext. or sanitize
if (bSan) {
if ($('san-ask').checked)
clearBrowsingData($('san-time').selectedIndex);
else
clearBrowsingData(0);
}
else
runExt($('ext-path').value, $('ext-arg').value);
}
function $(id) {
return document.getElementById(id);
}
// win32 only
function getInstallPath(subkey) {
try {
var key = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
key.open(key.ROOT_KEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"+subkey,
key.ACCESS_READ);
var path = key.readStringValue("InstallLocation");
key.close();
return path;
}
catch(e) {
return 0;
}
}
function LOG(text) {
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(text);
}
}, 0);